home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
JCSM Shareware Collection 1993 November
/
JCSM Shareware Collection - 1993-11.iso
/
cl760
/
edgraphj.lzh
/
EXPANDME.EXE
/
lha
/
CURVFIT2.GRF
< prev
next >
Wrap
Text File
|
1992-11-19
|
4KB
|
90 lines
{------------------------------------------------------------------------
{ CURVFIT2.GRF - EdGraph demo file. Copyright (c) A Soft Answer, 1992.
{
{ Plot points, fit a regression equation, and write out the regression
{ results in a table. Then plot the residuals from the regression in a
{ separate graph on the same page.
{ Do the demo files INTRO.GRF and CURVFIT1.GRF before this one.
{
{ Type - AltV to see this demo, or
{ - AltP to print it, but first...SPECIFY WHAT PRINTER YOU ARE USING:
{--------------------------------------------------------------------------}
Printer=1; { Change the value to one of these, depending on your printer:}
{ 1 = Generic 9 pin dot matrix, }
{ 2..7 = Epson: 2=MX, 3=RX, 4=FX, 5=EX, 6=LX, 7=LQ }
{ 8..9 = IBM: 8=ProPrinter, 9=QuietWriter }
{ 10..11 = NEC 24 pin, Toshiba 24 pin }
{ 12..13 = HP: 12=DeskJet, 13=LaserJet }
{ 14 = PostScript printers }
{--------------------------------------------------------------------------}
PgHeight=190; {Available page height in mm}
PgWidth =150; {Available page width in mm }
Initialise(Printer,PgHeight,PgWidth,1,1,"PRN");
x1=0; y1=0; x2=100; y2=20;
NewPlot(x1,y1,x2,y2,30,100,20,80,0,0);
xaxis("",y2,x1,20,2,2,0,0);
yaxis("",x2,y1,5,2,2,0,0);
xaxis("X-Axis",y1,x1,20,1,2,2,1);
yaxis("Y-Axis",x1,y1,5,1,2,2,1);
{ Define a procedure to generate the data points, as they will need to }
{ be read twice (once for the regression, and again for residuals) }
a=18; b=50; c=-625;
Procedure Data;
For i=0 to 100 step 4; {Generate data from math expressions }
{The 'sin' term adds errors. You could }
{also use the 'random' function. }
i a*exp(sqr(i-b)/c)+sin(10*i)/2;
EndFor;
EndProc;
{ Now plot some points and fit a regression equation. Place the cursor on }
{ the word "points" and press F1 for help with the use of the command. }
Join=20; {The regression equation to fit.}
SelectLine(1); {Select line style 1}
Points(1,2,0,0,2,6,Join,100,0,0,0,"");
Data; { ie. read the lines from Procedure Data; }
EndPoints;
If Join>2;
Shadow(1,1,0); {specify shadow style for the box}
Box(5,19.5,75,24,0); {draw a box and clear inside}
textstyle(0,0,1); { underline }
MoveTo(8,23);
textln("Regression [",Eqn(Join),"]");
textstyle(0,0,0); {cancel underline}
format(4,2,1,0);
textln(" a = ",curvefita," c = ",curvefitc);
textln(" b = ",curvefitb," r = ",curvefitr);
Endif;
{--------------------------------------------------------------------}
{ Now start the residuals graph
{--------------------------------------------------------------------}
y1=-1.5; y2=1.5; {expected range of residuals}
NewPlot(x1,y1,x2,y2,30,100,140,40,0,0,0);
xaxis("",y2,x1,20,2,1,0,0);
yaxis("",x2,-2,1,2,2,0,0);
xaxis("x-data",y1,x1,20,1,1,0,1);
yaxis("Residuals",x1,-2,1,1,2,2,1);
selectline(1);
line(x1,0,x2,0);
clip(1);
{ Now plot the residuals from the last regression. You MUST have first done}
{ the regression, which puts the correct values into variables curvefita, }
{ curvefitb & curvefitc. These values are then used by the Points command }
{ to plot the residuals on the y-axis vs the x-data on the x-axis }
{ (residuals are the differences between the data and the fitted function).}
Points(1,2,0,0,3,4,-Join,100,0,""); { -Join means plot residuals }
Data;
EndPoints;